<?php


namespace support;


use teamones\ucenter\Server;

/**
 * 用户中心调用对象代理类
 * Class UCenterService
 * @package support
 */
class UCenterService
{
    /** @var Server */
    private static Server $instance;

    /**
     * 获取用户中心调用实例
     * @return Server
     */
    public static function getInstance(): Server
    {
        if (empty(self::$instance)) {
            self::$instance = Server::getInstance([
                'debug' => config('app.debug'),
                'server_name' => 'teamones-im'
            ]);
        }
        self::$instance->setXUserInfo(self::getXUserInfo());
        return self::$instance;
    }

    /**
     * 获得xUserInfo
     * @return string
     */
    public static function getXUserInfo(): string
    {
        $request = request();
        if ($request instanceof Request) {
            return $request->getXUserInfo();
        } else {
            return "";
        }
    }

    /**
     * 不允许直接实例化当前对象
     * UCenterService constructor.
     */
    private function __construct()
    {
    }
}
